#!/usr/bin/perl -w
use strict;
use Includes;
use CGI qw/:standard *table *div -nosticky/;
use CGI::Pretty qw/ :html3 /;

my $c = new CGI;
my ($to,$from,$body) = (
		'secretary',
		'CHANGE_ME',
		$c->param('body')
		);

my $subject = sprintf('Message from %s',$from);
my $SUCCESS = 0;

# Make the basic HTML and form 
print header(-type=>'text/html'),
			Includes::get_html('Mail Sent'),
			div({id=>'main',class=>'rounded'},
					Includes::get_banner(),
					&send_mail( $to,$from,$subject,$body)
				 ),
			end_html();

sub send_mail($$$){
	my($to,$from,$subject,$body) = @_;
	my $retval;
	if($to && $from && $subject && $body){
		open(MAIL,"|/usr/sbin/sendmail -t");
		printf MAIL "To: %s\n",$to;
		printf MAIL "From: %s\n",$from;
		printf MAIL "Subject: %s\n",$subject;
		printf MAIL "%s",$body;
		close MAIL;
		$retval = 
			sprintf("Mail sent");
		$SUCCESS = 1;
	}else{
		$retval = "Message not sent, please try again";
	}
	return $retval ? div({id=>'status',
			class=>$SUCCESS?'success':'error'},$retval) : '';
}
